package com.julis.activity.setting.user;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.baseutils.SpfUtils;
import com.github.czy1121.view.RoundButton;
import com.julis.R;
import com.julis.db.Z_UserInfoDao;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 修改密码
 */
public class UserXiuGai_Activity extends AppCompatActivity {
    @BindView(R.id.img_back)
    RelativeLayout imgBack;
    @BindView(R.id.textView22)
    TextView textView22;
    @BindView(R.id.et_phone)
    EditText etPhone;
    @BindView(R.id.textView23)
    TextView textView23;
    @BindView(R.id.et_mm)
    EditText etMm;
    @BindView(R.id.textView24)
    TextView textView24;
    @BindView(R.id.et_qrmm)
    EditText etQrmm;
    @BindView(R.id.bt_Start)
    RoundButton btGetCode;
    @BindView(R.id.activity_main)
    LinearLayout activityMain;
    Z_UserInfoDao z_userInfoDao;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xiugai);
        String name = (String) SpfUtils.get(this, "name", "");
        ButterKnife.bind(this);
        etPhone.setText(name);
        etPhone.setEnabled(false);
        z_userInfoDao = new Z_UserInfoDao(this);

    }


    @OnClick({R.id.img_back, R.id.bt_Start})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.bt_Start:

                if (TextUtils.isEmpty(etMm.getText().toString())) {
                    Toast.makeText(this, "请输入密码", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (etMm.getText().toString().length() < 6 || etQrmm.getText().toString().length() < 6) {
                    Toast.makeText(this, "密码太短，请重新输入！", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (!etMm.getText().toString().equals(etQrmm.getText().toString())) {
                    Toast.makeText(this, "两次输入的密码不同，请重新输入！", Toast.LENGTH_SHORT).show();
                    return;
                }
//                if (z_userInfoDao.shifoucunzai(etPhone.getText().toString())) {
//                    Toast.makeText(this, "账号已存在", Toast.LENGTH_SHORT).show();
//                    return;
//                } else {
//                    z_userInfoDao.addUser(etPhone.getText().toString(), etMm.getText().toString());
//                    Toast.makeText(this, "注册成功", Toast.LENGTH_SHORT).show();
//                    finish();
//                }
                z_userInfoDao.updateUser(etPhone.getText().toString(), etQrmm.getText().toString());
                Toast.makeText(this, "修改用户密码成功！", Toast.LENGTH_SHORT).show();
                finish();
                break;
        }
    }
}
